//
//  common.cpp
//  yuzon
//
//  Created by Alvin on 2023/4/4.
//

#include "common.hpp"

using namespace cv;
using namespace std;

// human detector
int kHumanInputWidth = 192;
int kHumanInputHeight = 192;
float kHumanThreshold = 0.7f;

// keypoint detector
int kKeypointInputWidth = 96;
int kKeypointInputHeight = 128;
float kKeypointThreshold = 0.4f;
bool kDark = true;

// pipeline
bool kDrawBbox = true;
bool kDrawPose = true;
int kBboxLineThickness = 2;
int kPoseKeypointNum = 17;
int kPoseCircleRadius = 2;
int kPoseLineThickness = 3;

// scorer
vector<float> kStartAngle{
  90.0f, 90.0f, 90.0f, 90.0f, 0.0f, 0.0f, 0.0f, 0.0f, 7.025f, 7.025f
};
vector<int> kFrameOffsets{-8, -4, 0, 4, 8};

// smoother
float kFcMin = 0.5f;
float kB = 0.3f;
float kFcD = 1.0f;

// utils
double kColors[] = {
  // colors from https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.6/ppdet/utils/colormap.py
  0.000, 0.447, 0.741,
  0.850, 0.325, 0.098,
  0.929, 0.694, 0.125,
  0.494, 0.184, 0.556,
  0.466, 0.674, 0.188,
  0.301, 0.745, 0.933,
  0.635, 0.078, 0.184,
  0.300, 0.300, 0.300,
  0.600, 0.600, 0.600,
  1.000, 0.000, 0.000,
  1.000, 0.500, 0.000,
  0.749, 0.749, 0.000,
  0.000, 1.000, 0.000,
  0.000, 0.000, 1.000,
  0.667, 0.000, 1.000,
  0.333, 0.333, 0.000,
  0.333, 0.667, 0.000,
  0.333, 1.000, 0.000,
  0.667, 0.333, 0.000,
  0.667, 0.667, 0.000,
  0.667, 1.000, 0.000,
  1.000, 0.333, 0.000,
  1.000, 0.667, 0.000,
  1.000, 1.000, 0.000,
  0.000, 0.333, 0.500,
  0.000, 0.667, 0.500,
  0.000, 1.000, 0.500,
  0.333, 0.000, 0.500,
  0.333, 0.333, 0.500,
  0.333, 0.667, 0.500,
  0.333, 1.000, 0.500,
  0.667, 0.000, 0.500,
  0.667, 0.333, 0.500,
  0.667, 0.667, 0.500,
  0.667, 1.000, 0.500,
  1.000, 0.000, 0.500,
  1.000, 0.333, 0.500,
  1.000, 0.667, 0.500,
  1.000, 1.000, 0.500,
  0.000, 0.333, 1.000,
  0.000, 0.667, 1.000,
  0.000, 1.000, 1.000,
  0.333, 0.000, 1.000,
  0.333, 0.333, 1.000,
  0.333, 0.667, 1.000,
  0.333, 1.000, 1.000,
  0.667, 0.000, 1.000,
  0.667, 0.333, 1.000,
  0.667, 0.667, 1.000,
  0.667, 1.000, 1.000,
  1.000, 0.000, 1.000,
  1.000, 0.333, 1.000,
  1.000, 0.667, 1.000,
  0.167, 0.000, 0.000,
  0.333, 0.000, 0.000,
  0.500, 0.000, 0.000,
  0.667, 0.000, 0.000,
  0.833, 0.000, 0.000,
  1.000, 0.000, 0.000,
  0.000, 0.167, 0.000,
  0.000, 0.333, 0.000,
  0.000, 0.500, 0.000,
  0.000, 0.667, 0.000,
  0.000, 0.833, 0.000,
  0.000, 1.000, 0.000,
  0.000, 0.000, 0.167,
  0.000, 0.000, 0.333,
  0.000, 0.000, 0.500,
  0.000, 0.000, 0.667,
  0.000, 0.000, 0.833,
  0.000, 0.000, 1.000,
  0.000, 0.000, 0.000,
  0.143, 0.143, 0.143,
  0.286, 0.286, 0.286,
  0.429, 0.429, 0.429,
  0.571, 0.571, 0.571,
  0.714, 0.714, 0.714,
  0.857, 0.857, 0.857,
  1.000, 1.000, 1.000
};

// visualizer
map<int, vector<vector<int>>> kEdges{
  {17, {
    {0, 1}, {0, 2}, {1, 3}, {2, 4}, {3, 5}, {4, 6}, {5, 7}, {6, 8}, {7, 9},
    {8, 10}, {5, 11}, {6, 12}, {11, 13}, {12, 14}, {13, 15}, {14, 16}, {11, 12}
  }},
  {14, {
    {0, 1}, {1, 2}, {1, 3}, {2, 4}, {3, 5}, {4, 6}, {5, 7},
    {2, 8}, {3, 9}, {8, 10}, {9, 11}, {10, 12}, {11, 13}, {8, 9}
  }}
};
vector<Scalar> kColorMap{
  // colors from https://loading.io/color/feature/Rainbow/
  {230, 38, 31, 255},
  {235, 117, 50, 255},
  {247, 208, 56, 255},
  {163, 224, 72, 255},
  {73, 218, 154, 255},
  {52, 187, 230, 255},
  {67, 85, 219, 255},
  {210, 59, 231, 255},
  {240, 240, 240, 255}
};
map<int, vector<int>> kColorIndexes{
  {17, {
    0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 5
  }},
  {14, {
    0, 1, 1, 2, 2, 3, 3, 1, 1, 4, 4, 5, 5, 1
  }}
};
